var express = require('express');
const Token = require('../util/token')
const login = require('./login')
const manager = require("./manager");
const goods = require("./goods")
const goods_skus_card = require("./goods_skus_card")
const goods_skus_card_value = require("./goods_skus_card_value")
const image_class = require("./image_class")
const image = require("./image")
const category = require("./category")
const Result = require('../lib/Result');
const skus = require("./skus")
const last=require("./last")
const coupon=require("./coupon")
const notice=require("./notice")
const user_level=require("./user_level")
const goods_comment=require("./goods_comment")
var router = express.Router();
/**
 * 登录
 */
router.use("/login", login)
/**
 * token 验证中间件
 */
router.use(Token.getuseToken())
/* 管理员操作 */
router.use("/",last)
router.use("/manager", manager)
router.use("/goods", goods)
router.use("/goods_skus_card", goods_skus_card)
router.use("/goods_skus_card_value", goods_skus_card_value)
router.use("/image_class", image_class)
router.use("/image", image)
router.use("/category", category)
router.use("/skus", skus)
router.use("/coupon",coupon)
router.use("/notice",notice)
router.use("/user_level",user_level)
router.use("/goods_comment",goods_comment)
/**
 * 错误捕获
 */
router.use((err, req, res, next) => {
    if (err.name === 'UnauthorizedError') {
        console.log(err);
        return res.json(Result.unauthenticated())
    } else {
        console.log(err);
        return res.json(Result.unknownError(err.name))
    }
})
module.exports = router;